﻿using System;
using System.Collections;
using System.Data;
using System.Data.OracleClient;
using System.Linq;
using System.Xml.Linq;
using WPFExcelReport;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC:BaseFunction
    {
        public DateTime tomorrow = DateTime.Now.AddDays(1);
        public DateTime yesterday = DateTime.Now.AddDays(-1);
        public string ITXMANDANT = "00", ITXUSER = "ITXVVVK ", ITXDATE = "20120723";
        public string today = "";
        public string Right(string str, int num)
        {
            try
            {
                int leng = str.Length;
                str = str.Substring(leng - num, num);
            }
            catch (Exception ex)
            {
            }
            return str;
        }
        public string Left(string str, int num)
        {
            try
            {
                int leng = str.Length;
                str = str + "                                                                                ";
                str = str.Substring(0, num);
            }
            catch (Exception ex)
            {

            }
            return str;
        }
        OracleCommand or1;
        public OracleConnection OracleDB;
        public string ApplicationPath
        {
            get { return System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); }
        }
        public INTEXDBC(OracleConnection _OracleDB, IntexReptServBLClient _proxy)
        {
            OracleDB = _OracleDB;
            proxy = _proxy;
        }
        #region======A==============
        public void SaveAPZUORD(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QuerAPZUORD(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapAPZUORD(ref dwLocal, dwData);

            if (!flgExist)
            {
                InserAPZUORD(dwLocal);
            }

            UpdateAPZUORD(dwLocal);
        }
        #endregion

        #region======B==============        
        public void SaveBASTGA(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryBASTGA(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapBASTGA(ref dwLocal, dwData);
            InsertBASTGA(dwLocal);
            UpdateBASTGA(dwLocal);
        }
        public void SaveBHSATZ(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryBHSATZ(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapBHSATZ(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertBHSATZ(dwLocal);
            }
            UpdateBHSATZ(dwLocal);
        }
        public void SaveBSGROE(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryBSGROE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapBSGROE(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertBSGROE(dwLocal);
            }
            UpdateBSGROE(dwLocal);
        }
        public void SaveBSFARB(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryBSFARB(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapBSFARB(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertBSFARB(dwLocal);
            }
            UpdateBSFARB(dwLocal);
        }
        public void SaveBSSATZ(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryBSSATZ(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapBSSATZ(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertBSSATZ(dwLocal);
            }
            UpdateBSSATZ(dwLocal);
        }

        #endregion

        #region======C==============
        #endregion

        #region======D==============
        #endregion

        #region======E==============
        #endregion

        #region======F==============
        #endregion

        #region======G==============
        public void SaveGSCOLOR(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryGSCOLOR(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapGSCOLOR(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertGSCOLOR(dwLocal);
            }
            UpdateGSCOLOR(dwLocal);
        } 
        #endregion

        #region======H==============
        #endregion

        #region======K==============
        //KDSTAMM KUNDVER
        public void SaveKDSTAMM(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryKDSTAMM(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapKDSTAMM(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertKDSTAMM(dwLocal);
            }
            UpdateKDSTAMM(dwLocal);

        }
        public void SaveKUNDVER(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryKUNDVER(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapKUNDVER(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertKUNDVER(dwLocal);
            }
            UpdateKUNDVER(dwLocal);

        }
        #endregion

        #region======L==============
        #endregion

        #region======M==============
        #endregion

        #region======P==============
        #endregion

        #region======Q==============
        #endregion

        #region=====S==============
        public void SaveSDDAT(DataRow dwSDDAT)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;

            setResult = QuerySDDAT(dwSDDAT);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            if (!flgExist)
            {
                InsertSDDAT(dwSDDAT);
            }
        }
        #endregion

        #region======W==============
        public void SaveWAFARBEN(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWAFARBEN(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWAFARBEN(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWAFARBEN(dwLocal);
            }
            UpdateWAFARBEN(dwLocal);
        }
        public void SaveWASTAMM(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            bool IsUseCurrentWS05 = true;
            setResult = QueryWASTAMM(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWASTAMM(ref dwLocal, dwData, flgExist, IsUseCurrentWS05);

            if (!flgExist)
            {
                InsertWASTAMM(dwLocal);
            }
            UpdateWASTAMM(dwLocal);
        }
        public void SaveWASTKE(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWASTKE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWASTKE(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWASTKE(dwLocal);
            }
            UpdateWASTKE(dwLocal);
        }
        public void SaveWASTGA(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWASTGA(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWASTGA(ref dwLocal, dwData);

            InsertWASTGA(dwLocal);
            UpdateWASTGA(dwLocal);
        }
        public void SaveWASTPASS(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWASTPASS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWASTPASS(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWASTPASS(dwLocal);
            }
            UpdateWASTPASS(dwLocal);
        }
        public void SaveWBBEW(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWBBEW(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWBBEW(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWBBEW(dwLocal, ITXDBVERSION);
            }
            UpdateWBBEW(dwLocal);
        }
        public void SaveWBBST(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWBBST(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWBBST(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWBBST(dwLocal, ITXDBVERSION);
            }
            UpdateWBBST(dwLocal);
        }
        public void SaveWBDAT(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWBDAT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWBDAT(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWBDAT(dwLocal);
            }
            UpdateWBDAT(dwLocal);
        }
        public void SaveWDECK(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWDECK(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWDECK(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWDECK(dwLocal);
            }
            UpdateWDECK(dwLocal);
        }
        public void SaveWTEINZ(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTEINZ(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWTEINZ(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWTEINZ(dwLocal);
            }
            UpdateWTEINZ(dwLocal);
        }
        public void SaveWTGEW(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTGEW(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWTGEW(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWTGEW(dwLocal);
            }
            UpdateWTGEW(dwLocal);
        }
        public void SaveWTPASS(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTPASS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWTPASS(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWTPASS(dwLocal);
            }
            UpdateWTPASS(dwLocal);
        }
        public void SaveWTSCHUSS(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTSCHUSS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWTSCHUSS(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWTSCHUSS(dwLocal);
            }
            UpdateWTSCHUSS(dwLocal);
        }
        public void SaveWTSAER(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTSAER(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWTSAER(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWTSAER(dwLocal);
            }
            UpdateWTSAER(dwLocal);
        }
        #endregion
        
        #region======V==============
        public void SaveVKKOPF(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryVKKOPF(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapVKKOPF(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertVKKOPF(dwLocal, ITXDBVERSION);
            }
            UpdateVKKOPF(dwLocal);

        }
        public void SaveVKPOS(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVKPOS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapVKPOS(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertVKPOS(dwLocal, ITXDBVERSION);
            }
            UpdateVKPOS(dwLocal);

        }
        public void SaveVVLIEF(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVVLIEF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVVLIEF(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVVLIEF(dwLocal, ITXDBVERSION);
            }
            UpdateVVLIEF(dwLocal);
        }
        public void SaveVVTLIEF(DataRow dwData,string ITXDBVERSION="50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVVTLIEF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVVTLIEF(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertVVTLIEF(dwLocal,ITXDBVERSION);
            }
            UpdateVVTLIEF(dwLocal);
        }
        #endregion
    }
}